package com.zoe.app.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.zoe.app.entity.Student;
import com.zoe.app.entity.User;
import com.zoe.app.util.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zoe.Zhang
 * @date 2022/06/10
 * @description
 */
@RestController
public class StudentController {
    @GetMapping("/")
    public R<Student> studentR() {
        Student student = new Student();
        student.setId(1);
        student.setName("小红");
        student.setSex("1");
        return R.success(student);
    }

    @GetMapping("/list")
    public R<List<Student>> studentRList() {
        ArrayList<Student> studentArrayList = CollUtil.newArrayList();
        Student boy = new Student();
        boy.setId(1);
        boy.setName("小明");
        boy.setSex("1");

        Student girl = new Student();
        girl.setId(2);
        girl.setName("小红");
        girl.setSex("2");


        Student girl1 = new Student();
        girl1.setId(3);
        girl1.setName("小蓝");
        girl1.setSex("2");

        studentArrayList.add(boy);
        studentArrayList.add(girl);
        studentArrayList.add(girl1);
        return R.success(studentArrayList);
    }

    @GetMapping("/list-user")
    public R<List<Student>> ListUser() {
        User user = new User();
        user.setLevel("1");
        user.setMobile("131");
        user.setSex("1");
        User user2 = new User();
        user.setLevel("2");
        user.setMobile("132");
        user.setSex("2");

        ArrayList<User> users = ListUtil.toList(user2, user);

        ArrayList<Student> studentArrayList = CollUtil.newArrayList();
        Student boy = new Student();
        boy.setId(1);
        boy.setName("小明");
        boy.setSex("1");
        boy.setUser(user);
        boy.setUsers(users);

        Student girl = new Student();
        girl.setId(2);
        girl.setName("小红");
        girl.setSex("2");


        Student girl1 = new Student();
        girl1.setId(3);
        girl1.setName("小蓝");
        girl1.setSex("2");

        studentArrayList.add(boy);
        studentArrayList.add(girl);
        studentArrayList.add(girl1);
        return R.success(studentArrayList);
    }
}
